/*    */ package com.zimbra.cs.redolog.op;
/*    */ 
/*    */ import com.zimbra.common.account.Key.AccountBy;
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.MailboxManager;
/*    */ import com.zimbra.cs.mailbox.MailboxOperation;
/*    */ import com.zimbra.cs.redolog.MailboxIdConflictException;
/*    */ import com.zimbra.cs.redolog.RedoException;
/*    */ import com.zimbra.cs.redolog.RedoLogInput;
/*    */ import com.zimbra.cs.redolog.RedoLogOutput;
/*    */ import java.io.IOException;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class CreateMailbox
/*    */   extends RedoableOp
/*    */ {
/*    */   private String mAccountId;
/*    */   
/*    */   public CreateMailbox()
/*    */   {
/* 41 */     super(MailboxOperation.CreateMailbox);
/*    */   }
/*    */   
/*    */   public CreateMailbox(String accountId) {
/* 45 */     this();
/* 46 */     this.mAccountId = accountId;
/*    */   }
/*    */   
/*    */   protected String getPrintableData() {
/* 50 */     StringBuffer sb = new StringBuffer("account=").append(this.mAccountId != null ? this.mAccountId : "");
/* 51 */     return sb.toString();
/*    */   }
/*    */   
/*    */   protected void serializeData(RedoLogOutput out) throws IOException {
/* 55 */     out.writeUTF(this.mAccountId);
/*    */   }
/*    */   
/*    */   protected void deserializeData(RedoLogInput in) throws IOException {
/* 59 */     this.mAccountId = in.readUTF();
/*    */   }
/*    */   
/*    */   public void redo() throws Exception {
/* 63 */     int opMboxId = getMailboxId();
/* 64 */     Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(this.mAccountId, false);
/*    */     
/* 66 */     if (mbox == null) {
/* 67 */       Account account = Provisioning.getInstance().get(Key.AccountBy.id, this.mAccountId);
/* 68 */       if (account == null) {
/* 69 */         throw new RedoException("Account " + this.mAccountId + " does not exist", this);
/*    */       }
/*    */       
/* 72 */       mbox = MailboxManager.getInstance().createMailbox(getOperationContext(), account);
/* 73 */       if (mbox == null)
/*    */       {
/* 75 */         throw new RedoException("unable to create mailbox for accountId " + this.mAccountId, this);
/*    */       }
/*    */     }
/*    */     
/* 79 */     int mboxId = mbox.getId();
/* 80 */     if (opMboxId == mboxId) {
/* 81 */       mLog.info("Mailbox " + opMboxId + " for account " + this.mAccountId + " already exists");
/* 82 */       return;
/*    */     }
/* 84 */     throw new MailboxIdConflictException(this.mAccountId, opMboxId, mboxId, this);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/CreateMailbox.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */